package 力扣._343整数拆分;

import java.util.Arrays;

public class Solution {
    public int integerBreak(int n) {
        //将整数拆为尽可能相同的值，这样乘积才会最大
        //dp[i]: 对i进行拆分的最大乘积
        //dp[i] = max(j*(i-j), j*dp[i-j])
        int[] dp = new int[n + 1];
        dp[0] = 0;
        dp[1] = 0;
        dp[2] = 1;
        for (int i = 3; i <= n; i++) {
            for (int j = 1; j < i; j++) {
                int t = Math.max(j * (i - j), j * dp[i - j]);
                dp[i] = Math.max(t, dp[i]);
            }
        }
//        System.out.println(Arrays.toString(dp));
        return dp[n];
    }

    public static void main(String[] args) {
        int i = new Solution().integerBreak(10);
        System.out.println(i);
    }
}
